package com.saas.util;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Properties;


public class SaasConfig {
	
	public static String mongoDBHOSTS;
	public static String momgoDBPORTS;
	
	public static String mongoDBIP;
	public static String mongoDBPORT;
	
	/** mogoDB 名称 */
	public static String mongoDBName;
	public static String mongoDBCheck;
	/** mongodb连接数 */
	public static String mongodbConnectionsCount;

	public static Boolean publishFilter;
	public static Boolean addAPIFilter;
	public static Boolean remoteGrab;
	public static String remoteGrabUrl;
	
	public static String uploadFileDirector;
	public static String imgUrl;
	
	public static String messageTitle;
	
	public static String smsChannelTrigger;
	
	public static String notifyUrl;
	
	private static final String CONFIG_NAME = "application.properties";
	
	static{
		try {
			InputStream in = ClassLoader.getSystemResourceAsStream(CONFIG_NAME);
			try {
				if(in==null){
					URL resource = SaasConfig.class.getClassLoader().getResource(CONFIG_NAME);
					if (null!=resource){
						String filename = new URI(resource.toString()).toString();
						File file = new File(filename.replace("file:", ""));
						in = new FileInputStream(file);
					}
				}
			} catch (URISyntaxException e) {
				e.printStackTrace();
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			Properties p = new Properties();
			p.load(in);
			/**
			 * mongodb配置
			 */
			mongoDBName= p.getProperty("mongoDBName");
			mongodbConnectionsCount= p.getProperty("mongodbConnectionsCount");

			mongoDBHOSTS = p.getProperty("mongoDBHOSTS");
			momgoDBPORTS = p.getProperty("mongoDBPORTS");
			mongoDBIP= p.getProperty("mongoDBIP");
			mongoDBPORT= p.getProperty("mongoDBPORT");
			mongoDBCheck= p.getProperty("mongoDBCheck");
			uploadFileDirector = p.getProperty("uploadFileDirector");
			imgUrl = p.getProperty("imgUrl");
			messageTitle = p.getProperty("messageTitle");
			smsChannelTrigger = p.getProperty("smsChannelTrigger");
			publishFilter = DataUtils.isNotEmpty(p.getProperty("publishFilter"))?Boolean.valueOf(p.getProperty("publishFilter")):true;
			addAPIFilter = DataUtils.isNotEmpty(p.getProperty("addAPIFilter"))?Boolean.valueOf(p.getProperty("addAPIFilter")):true;
			remoteGrab = DataUtils.isNotEmpty(p.getProperty("remoteGrab"))?Boolean.valueOf(p.getProperty("remoteGrab")):false;
			remoteGrabUrl = p.getProperty("remoteGrabUrl");
			notifyUrl=p.getProperty("notify.url");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
